package com.sunk.fenbushishiwu.dtp.atomikos.config;

import com.atomikos.jdbc.AtomikosDataSourceBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@EnableConfigurationProperties
@EnableTransactionManagement(proxyTargetClass = true)
public class MybatisConfiguration {
    /**
     * 配置account数据库前缀
     */
    final static String ACCOUNT_PREFIX = "spring.datasource.druid.account";
    /**
     * 配置redpacket数据库前缀
     */
    final static String RED_PREFIX = "spring.datasource.druid.red";

    final static Logger logger = LoggerFactory.getLogger(MybatisConfiguration.class);

    /**
     * 配置account数据库的数据源
     */
    @Bean(name = "AccountDataSource")
    @ConfigurationProperties(prefix = ACCOUNT_PREFIX)
    public DataSource accountDataSource(){
        return new AtomikosDataSourceBean();
    }
    /**
     * 配置REDpACKET数据库的数据源
     */
    @Bean(name = "RedPacketDataSource")
    @ConfigurationProperties(prefix = RED_PREFIX)
    public DataSource redPacketDataSource(){
        return new AtomikosDataSourceBean();
    }
}
